package com.dao;

import com.entity.TArticleStatus;
import com.entity.TArticleStatusExample;
import com.mapper.TArticleStatusMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by del on 16-5-7.
 */
@Component
public class TArticleStatusDao {

    @Autowired
    private TArticleStatusMapper tArticleStatusMapper;

    public boolean insert(TArticleStatus tArticleStatus){
        return tArticleStatusMapper.insert(tArticleStatus) == 1;
    }

    public boolean delete(Integer id){
        return tArticleStatusMapper.deleteByPrimaryKey(id) == 1;
    }

    public TArticleStatus update(TArticleStatus tArticleStatus){
        return tArticleStatusMapper.updateByPrimaryKey(tArticleStatus) == 1 ? tArticleStatus : null;
    }

    public TArticleStatus select(String aid){
        return tArticleStatusMapper.selectLatestByAid(aid);
    }

    public List<TArticleStatus> selectExample(TArticleStatusExample tArticleStatusExample) {
        return tArticleStatusMapper.selectByExample(tArticleStatusExample);
    }

    public TArticleStatus selectByAid(String aid) {
        TArticleStatusExample tArticleStatusExample = new TArticleStatusExample();
        tArticleStatusExample
                .createCriteria()
                .andAidEqualTo(aid);
        List<TArticleStatus> tArticleStatusList = tArticleStatusMapper.selectByExample(tArticleStatusExample);
        if (!tArticleStatusList.isEmpty()){
            return tArticleStatusList.get(0);
        }
        else {
            return null;
        }
    }
}
